package com.titaniume.activitiweb;

import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

/**
 *@program: activiti7_workflow
 *@description:  任务处理
 *@author: renfei.huang
 *@create: 2021-11-09 15:39
 */
@SpringBootTest
public class Part4_Task {

    @Autowired
    private TaskService taskService;


    //act_ru_task act_ru_identitylink
    //任务查询
    @Test
    public  void getTasks(){
        List<Task> list = taskService.createTaskQuery().list();
        for (Task tk : list) {
            System.out.println("Id："+tk.getId());
            System.out.println("Name："+tk.getName());
            System.out.println("Assignee："+tk.getAssignee());
        }
    }

    //查询我的代办任务
    @Test
    public void getTasksByAssignee(){
        List<Task> list = taskService.createTaskQuery()
                .taskAssignee("bajie")
                .list();
        for (Task tk : list) {
            System.out.println("Id："+tk.getId());
            System.out.println("Name："+tk.getName());
            System.out.println("Assignee："+tk.getAssignee());
        }
    }


    //任务完成后 act_ru_task act_ru_identitylink act_ru_execution 数据清空
    //执行任务
    @Test
    public void completeTask(){
        taskService.complete("2c26bc4e-429c-11ec-bbf6-8cec4b5c0c44");
        System.out.println("完成任务");

    }


    //拾取任务
    @Test
    public void claimTask(){
        Task task = taskService.createTaskQuery().taskId("0019d3b8-4134-11ec-b1ff-8cec4b5c0c44").singleResult();
        taskService.claim("0019d3b8-4134-11ec-b1ff-8cec4b5c0c44","bajie");
    }

    //归还与交办任务
    @Test
    public void setTaskAssignee(){
        Task task = taskService.createTaskQuery().taskId("0019d3b8-4134-11ec-b1ff-8cec4b5c0c44").singleResult();
        taskService.setAssignee("0019d3b8-4134-11ec-b1ff-8cec4b5c0c44","null"); //归还候选任务
        taskService.setAssignee("0019d3b8-4134-11ec-b1ff-8cec4b5c0c44","wukong");//交办
    }
}
